package com.local.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.local.dao.mapers.LocalMemberFinanceMapper;
import com.local.entity.vo.MemberFinanceVO;
import com.local.model.LocalMemberFinance;
import com.local.page.LocalMemberFinancePage;
import com.local.service.face.LocalMemberFinanceService;

@Service
public class LocalMemberFinanceServiceImpl implements LocalMemberFinanceService
{
	@Autowired
	private LocalMemberFinanceMapper localMemberFinanceMapper;

	@Override
	public List<LocalMemberFinance> queryMemberFinanceByPage(
			LocalMemberFinancePage<LocalMemberFinance> page)
	{
		Integer recordCount = localMemberFinanceMapper.countAllByPage(page);
		page.setTotalRecords(recordCount);
		List<LocalMemberFinance> list = localMemberFinanceMapper.queryByPage(page);
		page.setData(list);
		return list;
	}

	@Override
	public MemberFinanceVO queryMemberSumFinance(Date startTime, Date endTime)
	{
		
		MemberFinanceVO memberFinanceVO = new MemberFinanceVO();
		int count = 0;
		double money = 0.0;
		List<LocalMemberFinance> list = localMemberFinanceMapper.queryMemberSumFinance(startTime, endTime);
		for (LocalMemberFinance localMemberFinance : list)
		{
			count+=localMemberFinance.getCount();
			money+=localMemberFinance.getMoney();
			if("CREATE".equals(localMemberFinance.getStatus())){
				memberFinanceVO.setCreateCount(localMemberFinance.getCount());
				memberFinanceVO.setCreateSumMoney(localMemberFinance.getMoney());
			}else if("RENEW".equals(localMemberFinance.getStatus())){
				memberFinanceVO.setRenewCount(localMemberFinance.getCount());
				memberFinanceVO.setRenewSumMoney(localMemberFinance.getMoney());
			}
		}
		memberFinanceVO.setStartTime(startTime);
		memberFinanceVO.setEndTime(endTime);
		memberFinanceVO.setSumCount(count);
		memberFinanceVO.setSumMoney(money);
		return memberFinanceVO;
	}
	
}
